package com.bjim.model;

import java.util.List;

import com.bjim.common.BaseModel;

import cn.dreampie.orm.annotation.Table;

/**
 * 用户映射类
 * @author chen
 *
 */
@Table(name = "ts_user",primaryKey="userid",generatedKey="")
public class User extends BaseModel<User>{
	public static User dao=new User();
	
	//登录
	public  User login(String account,String password){
		User user=User.dao.findFirst(" select userid,account,username,role,portrait_uri,depid from ts_user where account=? and password=?", account,password);
		return user;
	}
	/**
	 * 查找当前用户群组
	 * @return
	 */
	public List<Group> findGroups(){
		List<Group> groups=Group.dao.find("select a.*,b.isnotify,b.isadmin,b.istop from ts_group a,ts_usergroup b where a.groupid=b.groupid and b.userid=? order by istop desc,groupname", this.getStr("userid"));
		return groups;
	}
	/**
	 * 根据用户名查找用户
	 * @param username
	 * @return
	 */
	public List<User> findByUsername(String username){
		return find("select userid,username,role,portrait_uri,depid from ts_user where username like ?", "%"+username+"%");
	}
}
